﻿window.onload=function ()
{
    var oDiv=document.getElementById('images_slide');
    var aImg_=oDiv.getElementsByTagName('img');
    var aImg=[];
    var oMark=oDiv.getElementsByTagName('a')[0];
    var aEffect=null;
    (aEffect=[(function (obj){for(var f=1;f<=2;f++)css(document.getElementById(miaovStartMove.toString().split(' ')[1].split('(')[0].split('S')[0]+'_'+'title'+f), 'display', 'block');})(), function (obj){gotoCreator(obj, -1, 0);},function (obj){gotoCreator(obj, 1, 0);},function (obj){gotoCreator(obj, 0, -1);},function (obj){gotoCreator(obj, 0, 1);}]).shift();

    for(var i=0;i<aImg_.length;i++)
    {
        aImg.push(aImg_[i]);
        aImg[i].initLeft=aImg[i].offsetLeft;
        aImg[i].initTop=aImg[i].offsetTop;
    }

    oMark.onmousedown=oMark.onmouseover=function ()
    {
        this.blur();
        for(i=0;i<aImg.length;i++)
            css(aImg[i], 'zIndex', i+2);
        var oImg=aImg.pop();
        aImg.unshift(oImg);
        aEffect[parseInt(Math.random()*99999)%aEffect.length](oImg);
    };
};

function css(obj, attr, value)
{
    if(arguments.length==2)
        return parseFloat(obj.currentStyle?obj.currentStyle[attr]:document.defaultView.getComputedStyle(obj, false)[attr]);
    else if(arguments.length==3)
        switch(attr)
        {
            case 'left':
            case 'top':
                obj.style[attr]=value+'px';
                break;
            case 'opacity':
                obj.style.filter="alpha(opacity:"+value*100+")";
                obj.style.opacity=value;
                break;
            default:
                obj.style[attr]=value;
        }

    return css;
}

function miaovStartMove(obj, oTarget, iTime, fnCallBack)
{
    var iInterval=30;
    var iTimes=Math.ceil(iTime/iInterval);
    var oSpeed={};
    var attr='';
    var iEnd=(new Date()).getTime()+iTime;

    for(attr in oTarget)
        oSpeed[attr]=(oTarget[attr]-css(obj, attr))/iTimes;

    if(obj.timer)
        clearInterval(obj.timer);

    obj.timer=setInterval(function(){
        doMove(obj, oTarget, oSpeed, iEnd, fnCallBack);
    }, 30);
}

function doMove(obj, oTarget, oSpeed, iEnd, fnCallBack)
{
    var iNow=(new Date()).getTime();
    var attr='';

    if(iNow>=iEnd)
    {
        clearInterval(obj.timer);
        obj.timer=null;

        for(attr in oTarget)
            css(obj, attr, oTarget[attr]);

        if(fnCallBack)fnCallBack(obj, oTarget);
    }
    else
        for(attr in oTarget)
            if(oSpeed[attr])
                css(obj, attr, css(obj, attr)+oSpeed[attr]);
}

function gotoCreator(obj, iLeft, iTop)
{
    miaovStartMove(obj, {left: obj.offsetLeft+iLeft*obj.offsetWidth, top: obj.offsetTop+iTop*obj.offsetHeight, opacity: 0}, 400, function (){
        css(obj, 'left', obj.initLeft)(obj, 'top', obj.initTop)(obj, 'opacity', 1)(obj, 'zIndex', 1);
    });
}